package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.WeekResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Order;
import com.ruoyi.system.service.IOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 充电订单信息Controller
 * 
 * @author ruoyi
 * @date 2025-06-28
 */
@RestController
@RequestMapping("/system/order")
public class OrderController extends BaseController
{
    @Autowired
    private IOrderService orderService;

    /**
     * 查询充电订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(Order order)
    {
        startPage();
        List<Order> list = orderService.selectOrderList(order);
        return getDataTable(list);
    }

    /**
     * 导出充电订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "充电订单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Order order)
    {
        List<Order> list = orderService.selectOrderList(order);
        ExcelUtil<Order> util = new ExcelUtil<Order>(Order.class);
        util.exportExcel(response, list, "充电订单信息数据");
    }

    /**
     * 获取充电订单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{oId}")
    public AjaxResult getInfo(@PathVariable("oId") Integer oId)
    {
        return success(orderService.selectOrderByOId(oId));
    }

    /**
     * 新增充电订单信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "充电订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Order order)
    {
        return toAjax(orderService.insertOrder(order));
    }

    /**
     * 修改充电订单信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "充电订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Order order)
    {
        return toAjax(orderService.updateOrder(order));
    }

    /**
     * 删除充电订单信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "充电订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{oIds}")
    public AjaxResult remove(@PathVariable Integer[] oIds)
    {
        return toAjax(orderService.deleteOrderByOIds(oIds));
    }

    /**
     * 查询今日充电度数
     */
    @GetMapping("/selectTodayc")
    public Double selectTodayc(){
        return orderService.selectTodayc();
    };

    /**
     * 查询今日充电次数
     */
    @GetMapping("/selectCountTodayc")
    public Integer selectCountTodayc(){
        return orderService.selectCountTodayc();
    };

    /**
     * 查询昨天充电度数
     */
    @GetMapping("/selectYesterdayc")
    public Double selectYesterdayc(){
        return orderService.selectYesterdayc();
    };

    /**
     * 查询昨天充电次数
     */
    @GetMapping("/selectCountYesterdayc")
    public Integer selectCountYseterdayc(){
        return orderService.selectCountYesterdayc();
    };

    /**
     * 查询本周充电度数
     */
    @GetMapping("/selectWeekc")
    public List<WeekResult> selectWeekc(){
        return orderService.selectWeekc();
    };

    /**
     * 查询本周充电度数
     */
    @GetMapping("/selectCountWeekc")
    public List<WeekResult> selectCountWeekc(){
        return orderService.selectCountWeekc();
    };

    /**
     * 查询本周充电度数
     */
    @GetMapping("/selectLastWeekc")
    public List<WeekResult> selectLastWeekc(){
        return orderService.selectLastWeekc();
    };

    /**
     * 查询本周充电度数
     */
    @GetMapping("/selectCountLastWeekc")
    public List<WeekResult> selectCountLastWeekc(){
        return orderService.selectCountLastWeekc();
    };

    /**
     * 查询支付方式占比
     */
    @GetMapping("/selectTypePercentage")
    public List<Map<String,Object>> selectTypePercentage(){
        return orderService.selectTypePercentage();
    };

    /**
     * 查询今日充电订单
     */
    @GetMapping("/selectTodayOrder")
    public List<Map<String,Object>> selectTodayOrder(){
        return orderService.selectTodayOrder();
    };
}
